fix: remove python-dateutil runtime dependency#540
Merged
marandaneto merged 5 commits intomainfrom Apr 28, 2026
Merged
Conversation
Contributor
Prompt To Fix All With AIThis is a comment left during a code review.
Path: posthog/feature_flags.py
Line: 777-787
Comment:
**`fromisoformat` rejects space-separated timezone offsets on Python 3.10**
`datetime.fromisoformat` on Python 3.10 does not accept a space between the time and the UTC-offset (e.g. `"2022-04-05 12:34:12 +01:00"`), raising a `ValueError`. Python 3.11 expanded `fromisoformat` to accept most ISO 8601 forms, but since `requires-python = ">=3.10"`, any property value string in that format will fail on 3.10 where `dateutil.parser.parse` previously succeeded. The test `test_parse_datetime_matches_dateutil_for_supported_formats` itself includes this exact case, so it will only pass on 3.11+. A simple normalisation before calling `fromisoformat` would cover it:
```python
def parse_datetime(value: str) -> datetime.datetime:
text = value.strip()
if text.endswith("Z"):
text = text[:-1] + "+00:00"
elif text.upper().endswith(" UTC"):
text = text[:-4] + "+00:00"
elif re.fullmatch(r"\d{4}", text):
now = datetime.datetime.now()
return datetime.datetime(int(text), now.month, now.day)
# Normalise "... +HH:MM" (space before offset) accepted by dateutil but not
# by fromisoformat on Python < 3.11.
text = re.sub(r" ([+-]\d{2}:\d{2})$", r"\1", text)
return datetime.datetime.fromisoformat(text)
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: posthog/test/test_feature_flags.py
Line: 4582-4589
Comment:
**Prefer parameterised test**
Per the project's simplicity rules, parameterised tests are preferred. The loop over a tuple of strings is equivalent to a parameterised test but hides failures behind a single test name and stops on the first failure, making it harder to diagnose which format broke.
```python
@parameterized.expand([
("iso_date", "2022-05-01"),
("iso_datetime_Z", "2022-04-05T12:34:12Z"),
("iso_datetime_utc", "2022-04-05 12:34:12 UTC"),
("iso_datetime_offset", "2022-04-05 12:34:12 +01:00"),
])
def test_parse_datetime_matches_dateutil_for_supported_formats(self, _name, value):
assert parse_datetime(value) == parser.parse(value)
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: remove python-dateutil runtime depe..." | Re-trigger Greptile |
Contributor
posthog-python Compliance ReportDate: 2026-04-28 14:46:23 UTC ✅ All Tests Passed!30/30 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 1/1 tests passed View Details
|
dustinbyrne
approved these changes
Apr 28, 2026
Contributor
dustinbyrne
left a comment
There was a problem hiding this comment.
One minor comment + greptile review looks legit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Fixes #109.
python-dateutilwas a runtime dependency of the SDK, and older supported dependency resolutions can emit Python 3.12+ deprecation warnings on import. The SDK only used a small subset of dateutil behavior, so this removes it from runtime dependencies while keeping compatibility covered in tests.💚 How did you test it?
uv run ruff check posthog sdk_compliance_adapteruv run pytest -quv run mypy --no-site-packages --config-file mypy.ini . | uv run mypy-baseline filteruv run python -W error::DeprecationWarning -c 'import posthog'📝 Checklist
If releasing new changes
sampo addto generate a changeset filereleaselabel to the PR